package cn.itrip.biz.controller;


import cn.itrip.biz.service.itripAreaDic.ItripAreaDicService;
import cn.itrip.biz.service.itripHotel.ItripHotelService;
import cn.itrip.biz.service.itripImage.ItripImageService;
import cn.itrip.biz.service.itripLabelDic.ItripLabelDicService;
import cn.itrip.common.DtoUtil;
import cn.itrip.dto.Dto;
import cn.itrip.pojo.ItripLabelDic;
import cn.itrip.vo.ItripAreaDicVO;
import cn.itrip.vo.ItripImageVO;
import cn.itrip.vo.ItripLabelDicVO;
import cn.itrip.vo.hotel.HotelVideoDescVO;
import cn.itrip.vo.hotel.ItripSearchDetailsHotelVO;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.sound.midi.Soundbank;
import java.util.ArrayList;
import java.util.List;

@RestController  //Controller+responseBody
@RequestMapping(value = "/api/hotel")
@Api(value = "biz测试HotelController",tags = "{biz测试HotelController}")
public class HotelController {

    @Resource
    private ItripLabelDicService itripLabelDicService;
    @Resource
    private ItripAreaDicService itripAreaDicService;
    @Resource
    private ItripHotelService itripHotelService;
    @Resource
    private ItripImageService itripImageService;

    /**
     * 查询酒店特色列表
     */
    @ApiOperation(value = "查询酒店特色列表")
    @RequestMapping(value = "/queryhotelfeature", method = RequestMethod.GET, produces = "application/json")
    public Dto queryhotelfeature() {
        try {
            List<ItripLabelDic> parentIdList = itripLabelDicService.getItripLabelDicByParentId(16l);
            List<ItripLabelDicVO> dicVOList=new ArrayList<>();
            for (int i=0;i<parentIdList.size();i++){
                //创建前端使用的ItripLabelDicVO实体类
                ItripLabelDicVO dicVO=new ItripLabelDicVO();
                dicVO.setId(parentIdList.get(i).getId());
                dicVO.setName(parentIdList.get(i).getName());
                dicVO.setDescription(parentIdList.get(i).getDescription());
                dicVO.setPic(parentIdList.get(i).getPic());
                dicVOList.add(dicVO);
            }
            return DtoUtil.returnDataSuccess(dicVOList);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常,获取失败", "10205");
        }
    }

    /**
     * 查询商圈
     */
    @ApiOperation(value = "根据城市查询商圈")
    @RequestMapping(value = "/querytradearea/{cityId}", method = RequestMethod.GET, produces = "application/json")
    public Dto querytradeareaCityId(@PathVariable("cityId") Integer cityId){
        try {

            //酒店所属商圈
            List<ItripAreaDicVO> hotelVideoDescVOs = itripAreaDicService.queryTradingAreaNameList(cityId);
            return DtoUtil.returnDataSuccess(hotelVideoDescVOs);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常,获取失败", "10204");
        }
    }

    /**
     *  根据targetId查询酒店图片(type=0)
     */
    @ApiOperation(value = "根据酒店ID查询酒店图片")
    @RequestMapping(value = "/getimg/{targetId}", method = RequestMethod.GET, produces = "application/json")
    public Dto getimgTargetId(@PathVariable("targetId") String targetId){
        try {
            if (targetId==null){
                return DtoUtil.returnFail(" 酒店id不能为空", "100213");
            }
            List<ItripImageVO> imgTargetId = itripImageService.getImgTargetId(targetId);
            System.err.println(JSON.toJSONString(imgTargetId));
            return DtoUtil.returnDataSuccess(imgTargetId);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("获取酒店图片失败", "100212");
        }
    }

    /**
     *  根据酒店id查询酒店特色、商圈、酒店名称
     */
    @ApiOperation(value = "根据酒店id查询酒店特色、商圈、酒店名称（视频文字描述）")
    @RequestMapping(value = "/getvideodesc/{hotelId}", method = RequestMethod.GET, produces = "application/json")
    public Dto getVideoDescHotelId(@PathVariable String hotelId){
        try {
            if (hotelId==null){
                return DtoUtil.returnFail("酒店id不能为空", "100215");
            }
            HotelVideoDescVO hotelVideoDescVO=new HotelVideoDescVO();
            //酒店所属商圈
            List<String> hotelVideoDescVOs = itripAreaDicService.queryIdAreaNameList(Integer.valueOf(hotelId));
            //根据酒店id获取酒店特色
            List<String>  featureIdList= itripAreaDicService.queryFeatureIdList(Integer.valueOf(hotelId));

            //获取酒店名称
            String homeName=itripHotelService.getItripHotelByName(hotelId);

            hotelVideoDescVO.setTradingAreaNameList(hotelVideoDescVOs);
            hotelVideoDescVO.setHotelFeatureList(featureIdList);

            return DtoUtil.returnDataSuccess(hotelVideoDescVO);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("获取酒店视频文字描述失败", "100214");
        }
    }

    /**
     *  根据酒店id查询酒店设施
     */
    @ApiOperation(value = "根据酒店id查询酒店设施")
    @RequestMapping(value = "/queryhotelfacilities/{id}", method = RequestMethod.GET, produces = "application/json")
    public Dto queryHotelFacilitiesId(@PathVariable("id") Integer id){
        try {
            if (id==null){
                return DtoUtil.returnFail("酒店id不能为空", "10206");
            }
            String facilities= itripHotelService.queryHotelFacilitiesId(id);
            return DtoUtil.returnDataSuccess(facilities);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常,获取失败", "10207");
        }
    }

    /**
     *  查询热门城市
     */
    @ApiOperation(value = "查询国内、国外的热门城市(1:国内 2:国外)")
    @RequestMapping(value = "/queryhotcity/{type}", method = RequestMethod.GET, produces = "application/json")
    public Dto queryHotcityType(@PathVariable("type") Integer type){
        try {
            if (type==null){
                return DtoUtil.returnFail("hotelId不能为空", "10201");
            }
            List<ItripAreaDicVO> dicVo = itripAreaDicService.getItripAreaDicByIsChina(type);
            return DtoUtil.returnDataSuccess(dicVo);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常,获取失败", "10202");
        }
    }

    /**
     *  根据酒店id查询酒店特色和介绍
     */
    @ApiOperation(value = "根据酒店id查询酒店特色和介绍")
    @RequestMapping(value = "/queryhoteldetails/{id}", method = RequestMethod.GET, produces = "application/json")
    public Dto queryHotelDetailsId(@PathVariable("id") Integer id){
        try {
            if (id==null){
                return DtoUtil.returnFail("酒店id不能为空", "10210");
            }
            //酒店特色
            List<ItripSearchDetailsHotelVO> vo= itripHotelService.getItripLabelDicByParentId(id);
            //酒店描述
            String details=itripHotelService.getItripHotelByDetails(id);
            ItripSearchDetailsHotelVO de=new ItripSearchDetailsHotelVO();
            de.setName("酒店介绍");
            de.setDescription(details);
            vo.add(de);
            return DtoUtil.returnDataSuccess(vo);

        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常,获取失败", "10211");
        }
    }

    /**
     *  根据酒店id查询酒店政策
     */
    @ApiOperation(value = "根据酒店id查询酒店政策")
    @RequestMapping(value = "/queryhotelpolicy/{id}", method = RequestMethod.GET, produces = "application/json")
    public Dto queryHotelPolicyId(@PathVariable Integer id){
        try {
            if (id==null){
                return DtoUtil.returnFail("酒店id不能为空", "10208");
            }
            return DtoUtil.returnDataSuccess(itripHotelService.queryHotelPolicyId(id));
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常,获取失败", "10209");
        }
    }
}
